<!--
 * Description: TempCode新增页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Chengming.Li
 * Date: 2020/06/24 09:28
-->

<template>
  <div>
    <!--数据表单-->
    <el-form label-width="160px" :model="formData" size="mini">
      <el-row>
        <!--料号-->
        <el-col :span="12">
          <el-form-item label="New Part Number">
            <el-input v-model="formData.newPartNumber" v-blur:partNumber="formData" clearable />
          </el-form-item>
        </el-col>

        <!--gcmOwner-->
        <el-col :span="12">
          <el-form-item label="GCM Owner">
            <el-select
              v-model="formData.gcmOwner"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
              style="width: 100%; height: 100%"
            >
              <el-option
                v-for="item in gcmOwnerList(formData.gcmFunction)"
                :key="item.userName"
                :label="item.userName"
                :value="item.userId"
              >
                <span style="float: left;">{{ item.userName }}</span>
                <span style="float: right; color: #b4b4b4; font-size: 12px;margin-right: 25px">
                  {{ item.gcmFunction }}
                </span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!--gcmFunction-->
        <el-col :span="12">
          <el-form-item label="GCM Function">
            <el-select
              v-model="formData.gcmFunction"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
              style="width: 100%; height: 100%"
              @change="changeGcmFunction(formData.gcmFunction)"
            >
              <el-option
                v-for="item in $store.getters['enums/getGcmFunctionListOnly']"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <!--tempCode-->
        <el-col :span="12">
          <el-form-item label="Temp Code">
            <el-input v-model="formData.tempCode" />
          </el-form-item>
        </el-col>

        <!--commodity-->
        <el-col :span="12">
          <el-form-item label="Commodity">
            <el-select
              v-model="formData.commodity"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in commodityList(formData.gcmFunction)"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              >
                <span style="float: left">{{ item.name }}</span>
                <span style="float: right; color: #b4b4b4; font-size: 12px">
                  {{ item.gcmFunction }}
                </span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span style="display: block; text-align: center; margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button :loading="isRequesting" size="medium" type="primary" @click="save">
        {{ $t('button.save') }}
      </el-button>
    </span>
  </div>
</template>

<script>
import { tempCodeAdd } from '@/api/quote/fd-temp-code'

export default {
  name: 'TempCodeAdd',
  props: {},
  data() {
    return {
      // 正在查询
      isRequesting: false,
      formData: {}
    }
  },
  computed: {},
  methods: {
    async save() {
      try {
        this.isRequesting = true
        await tempCodeAdd({
          ...this.formData
        })
        this.$emit('save')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style scoped></style>
